<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models\Env;

use Carbon\Carbon;
use App\Models\Eloquent;

/**
 * Class QtpHostEnv
 *
 * @property int $id
 * @property string $name
 * @property string $remark
 * @property string $created_adminer
 * @property string $updated_adminer
 * @property int $enable
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 *
 * @package App\Models
 */
class HostEnv extends Eloquent
{
	protected $table = 'host_env';

	protected $casts = [
		'enable' => 'int'
	];

	protected $fillable = [
		'name',
		'remark',
		'created_adminer',
		'updated_adminer',
		'enable'
	];

    public static $fillables = [
        'name' => '环境标识名称',
        'remark' => '环境标识备注',
        'created_adminer' => '更新人',
        'updated_adminer' => '创建人',
        'enable' => '状态'
    ];

    public static function getByName(string $name): ?self
    {
        return self::where('name', $name)->first();
    }

    public function label()
    {
        $this->host_count = (int) Host::where('host_env_id', $this->id)->count();
        return $this;
    }
}
